package com.cskaoyan.shiro;


import com.cskaoyan.bean.User;
import com.cskaoyan.mapper.UserMapper;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class WxRealm extends AuthorizingRealm {

    @Autowired
    UserMapper userMapper;

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        //根据username获取数据库中对应的password
        MallToken token = (MallToken) authenticationToken;
        String username = token.getUsername();
        String password = userMapper.selectPasswordByName(username);

        String credential =  password;



        User user =  userMapper.selectUserByName(username);
       // System.out.println("我的user信息  -----------------------------" + user);
        SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user,credential,this.getName());
        return authenticationInfo;
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }


}
